package eliauk.fun.flowabledemo.config;

import cn.hutool.core.util.StrUtil;
import org.flowable.bpmn.model.Artifact;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.GraphicInfo;
import org.flowable.image.impl.DefaultProcessDiagramCanvas;
import org.flowable.image.impl.DefaultProcessDiagramGenerator;

import java.util.List;

public class CustomProcessDiagramGenerator extends DefaultProcessDiagramGenerator {
    @Override
    protected void drawArtifact(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, Artifact artifact) {
        super.drawArtifact(processDiagramCanvas, bpmnModel, artifact);
    }

    @Override
    protected void drawActivity(DefaultProcessDiagramCanvas processDiagramCanvas, BpmnModel bpmnModel, FlowNode flowNode, List<String> highLightedActivities, List<String> highLightedFlows, double scaleFactor, Boolean drawSequenceFlowNameWithNoLabelDI) {
        // Draw highlighted activities
        GraphicInfo graphicInfo = bpmnModel.getGraphicInfo(flowNode.getId());
        if (highLightedActivities.contains(flowNode.getId())) {
            if (StrUtil.containsAny(flowNode.getId(), "startEvent", "endEvent")
                    || StrUtil.equals(flowNode.getName(), "开始")
                    || StrUtil.equals(flowNode.getName(), "结束")) {
                // 开始结束节点设置为圆形
                ((CustomProcessDiagramCanvas) processDiagramCanvas).drawStartOrEndEventHighLight((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
            } else if (highLightedActivities.get(highLightedActivities.size() - 1).equals(flowNode.getId())) {
                // 这里判断是当前节点，设置为绿色高亮
            } else {
                // 已经完成的节点则设置为绿色
                ((CustomProcessDiagramCanvas) processDiagramCanvas).drawCompletedActivity((int) graphicInfo.getX(), (int) graphicInfo.getY(), (int) graphicInfo.getWidth(), (int) graphicInfo.getHeight());
            }
        }
    }

}
